package Thread;

public class Demo18 {
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            for(int i = 0; i < 5; i++){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t1结束");
        });
        Thread t2 = new Thread(()->{
            try {
                t1.join();//t2等待t1，并且和主线程没有关系
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2结束");
        });
        t1.start();
        t2.start();

        System.out.println("主线程结束");

        /*
        * 主线程结束
          t1结束
          t2结束
        * */
    }
}
